import java.util.Scanner;

public class Solution {
    public void moveZeroes(int[] nums){

        int left = 0;
        int right = -1;

//定义两个变量，让left先去遍历数组，把数组分为两个区间，已处理的和未处理的区间。
//接着让right去遍历已处理的区间，将其划分为非零区间和零区间
        for (left = 0; left < nums.length; left++) {
//left指向零元素时，不做任何处理
//当left指向非零元素时，互换把非零元素加入到左侧区间
            if(nums[left] != 0){
                right++;
                int tmp = nums[left];
                nums[left] = nums[right];
                nums[right] = tmp;
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int size = in.nextInt();
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = in.nextInt();
            }
            Solution solution = new Solution();
            solution.moveZeroes(array);
            for (int i = 0; i < array.length; i++) {
                System.out.print(array[i]+" ");
            }
        }
    }
}